<template>
  <div>
    <el-card shadow="hover" class="department" >
      <el-tabs v-model="activeName" @tab-click="handleClick">
        <!-- <el-tab-pane label="连续性肾脏替代治疗（CRRT）护理记录单一" name="first">
          <LuoxuanshanguangZhiliao :settings.sync="settings"></LuoxuanshanguangZhiliao>
        </el-tab-pane> -->
        <el-tab-pane label="CRRT质控" name="first">
          <Crrtpatientinquiry  v-if="firstUpdate"/>
        </el-tab-pane>
        <el-tab-pane label="连续性肾脏替代治疗（CRRT）护理记录单" name="second">
          <crrtNursing :settings="settings" v-if="secondUpdate" />
        </el-tab-pane>
        <!-- <el-tab-pane label="连续性肾脏替代治疗（CRRT）护理记录单三" name="fourth">
          <LuoxuanshanguangLuoxuanwan :settings="settings" />
        </el-tab-pane> -->
      </el-tabs>
    </el-card>
  </div>
</template>
<script>
import { printExcel } from "@/utils/config"; // 导入模块
import LuoxuanshanguangZhiliao from "../nursingDocument/LuoxuanshanguangZhiliao";
import crrtNursing from "./crrtNursing";
import LuoxuanshanguangLuoxuanwan from "../nursingDocument/LuoxuanshanguangLuoxuanwan";
import Crrtpatientinquiry from "../nursingDocument/crrtpatientinquiry";
import {} from "@/api/table";

export default {
  components: {
    LuoxuanshanguangZhiliao,
    crrtNursing,
    LuoxuanshanguangLuoxuanwan,
    Crrtpatientinquiry
  },
  data() {
    return {
      timeXSpan: 1,
      settings: {
        startDate: "2021-05-18", //查询起始日期
        startTime: "07:00:00",
        timeSpan: "24",
        timeType: "小时",
        loading: false, //查询中
      },
      timeTypeOptions: [
        { id: 0, type: "小时" },
        { id: 1, type: "天" },
      ],

      data: {},
      activeName: "second",
      firstUpdate: false,
      secondUpdate: true,
      thirdUpdate: false,
      fourthUpdate: false,
      page_rows: "",
      max_query_days: 3, //最大查询跨度，天
      loading:false
    };
  },
  computed: {
    getData() {
      return this.$store.state.user.severFall;
    },
  },
  watch: {
    getData() {
      this.data = this.$store.state.user.severFall;

    },
  },
  mounted() {
    this.data = this.data = this.$store.state.user.severFall;
  },
  methods: {
    //选择时间类型强制更新成7天时间
    selectTimeType(val) {
      if (val == "小时") {
        var hours=parseInt(this.settings.timeSpan)*24;
        if( hours<24) hours=24;
        else if( hours>24 * this.max_query_days) hours=24 * this.max_query_days;
        this.settings.timeSpan = hours;
      } else {
        var days=parseInt(this.settings.timeSpan)/24;
        if( days<1 ) days=1;
        else if( days>this.max_query_days) days=this.max_query_days;
        this.settings.timeSpan = days;
      }
      //this.dateChanged();
    },
    //选择时间强制更新成7天时间
    selectTimeSpan(val) {
      if (this.settings.timeType == "小时") {
        if (val >= 24 * this.max_query_days) {
          val = 24 * this.max_query_days;
        }
      } else {
        if (val > this.max_query_days) {
          val = this.max_query_days;
        }
      }
      this.settings.timeSpan = val;
      //console.log(val);
      //this.dateChanged();
    },
    dateChanged() {
      var temp = JSON.parse(JSON.stringify(this.settings));
      this.settings = temp;
      this.settings.loading=true;

    },
    saveSetting() {
      this.correctSettings();
      localStorage.setItem("nurse-settings", JSON.stringify(this.settings));
      this.$message({ message: "已保存", type: "success", duration: 800 });
    },
    readSetting() {
      // var yesterDay=new Date().getTime()-24*3600*1000;
      var yesterDay = new Date().getTime();
      this.settings.loading = false;
      this.settings.startDate = new Date(yesterDay).Format("yyyy-MM-dd");
      var str = localStorage.getItem("nurse-settings");
      if (str == null) {
        this.settings.startTime = "07:00:00";
        this.settings.timeSpan = "24";
        this.settings.timeType = "小时";
      } else {
        var json = JSON.parse(str);
        if (json != null) {
          this.settings.startTime = json.startTime;
          this.settings.timeSpan = json.timeSpan;
          this.settings.timeType = json.timeType;
        }
      }
    },
    correctSettings() {
      var dtStr = this.formattedTime(this.settings.startTime);
      if (dtStr == "") this.settings.startTime = "07:00:00";
      var dtStr = this.formattedDate(this.settings.startDate);
      if (dtStr == "") this.settings.startDate = this.getFullDate(new Date());

      var timeSpan = parseInt(this.settings.timeSpan);
      if (isNaN(timeSpan) || timeSpan < 1) {
        if (this.settings.timeType == "天") this.settings.timeSpan = 1;
        else this.settings.timeSpan = 24;
        var hours = 24;
      } else {
        if (this.settings.timeType == "天") var hours = timeSpan * 24;
        else var hours = timeSpan;
      }
      return hours;
    },
    formattedDate(dateStr) {
      if (typeof dateStr != "string" || dateStr.length < 8) return "";
      var tArray = dateStr.split("-");
      var n = tArray.length;

      if (n != 3) return "";
      for (var i = 0; i < n; i++) {
        if (tArray[i].length == 0) return "";
      }
      var year = parseInt(tArray[0]);
      if (year < 200) year += 2000;
      else if (year < 2000) return "";

      if (parseInt(tArray[1]) < 0 || parseInt(tArray[1]) > 11) return "";
      if (parseInt(tArray[2]) < 1 || parseInt(tArray[2]) > 31) return "";
      var str = year + "-" + tArray[1] + "-" + tArray[2];

      if (Date.parse(str)) return str;
      else return "";
    },
    //检查时间格式,允许 12:12,12:12:10,12:12:12:500三种格式，字符型
    //错误格式或值返回空
    //格式及值都正确，返回完整时间：12:12:10，字符型，毫秒忽略
    formattedTime(timeStr) {
      if (typeof timeStr != "string" || timeStr.length < 3) return "";
      var tArray = timeStr.split(":");
      var n = tArray.length;

      if (n < 2) return "";
      for (var i = 0; i < n; i++) {
        if (tArray[i].length == 0) return "";
      }
      if (parseInt(tArray[0]) < 0 || parseInt(tArray[0]) > 23) return "";
      if (parseInt(tArray[1]) < 0 || parseInt(tArray[1]) > 59) return "";
      if (n == 2) return timeStr + ":00";
      if (n > 2) {
        if (parseInt(tArray[2]) < 0 || parseInt(tArray[2]) > 59) return "";
        else return tArray[0] + ":" + tArray[1] + ":" + tArray[2];
      }
    },
    getFullDate(date) {
      var str = "" + date.getFullYear();

      if (date.getMonth() < 9) str += "-0" + (date.getMonth() + 1);
      else str += "-" + (date.getMonth() + 1);

      if (date.getDate() < 10) str += "-0" + date.getDate();
      else str += "-" + date.getDate();

      return str;
    },
    handleClick(tabName) {
      //return;
      if (this.activeName == "first") {
        this.firstUpdate = true;
        this.secondUpdate = false;
        this.thirdUpdate = false;
        this.fourthUpdate = false;
      } else if (this.activeName == "second") {
        this.firstUpdate = false;
        this.secondUpdate = true;
        this.thirdUpdate = false;
        this.fourthUpdate = false;
      } else if (this.activeName == "third") {
        this.firstUpdate = false;
        this.secondUpdate = false;
        this.thirdUpdate = true;
        this.fourthUpdate = false;
      } else if (this.activeName == "fourth") {
        this.firstUpdate = false;
        this.secondUpdate = false;
        this.thirdUpdate = false;
        this.fourthUpdate = true;
      }
    },

    onInput() {
      localStorage.setItem("settings", JSON.stringify(this.settings));
      var set = localStorage.getItem("settings");
      this.$store.commit("onInput", this.settings.page_rows);
    },
  },
};
</script>

<style>
.customer-table {
  border-top: 1px solid #000;
  border-left: 1px solid #000;
  border-bottom: 1px solid #000;
}
.customer-table td,
.customer-table th.is-leaf,
.customer-table thead.is-group th {
  border-right: 1px solid #000;
  border-bottom: 1px solid #000;
}
.customer-table .el-table__empty-block {
  border-right: 1px solid #000;
}
.tianwai {
  margin-right: 20px;
}
.feixian {
  margin-right: 35px;
}
</style>
<style lang="scss" scoped>
::v-deep body .el-table th.gutter {
  display: table-cell !important;
}
::v-deep .el-table td,
.el-table th {
  padding: 0 !important;
}
::v-deep .el-table td {
  height: 28px !important;
  line-height: 28px !important;
}
::v-deep .el-input__inner {
  padding: 0 !important;
  height: 28px !important;
}
::v-deep .el-table .cell {
  padding: 0 !important;
}
::v-deep .el-input--suffix .el-input__inner {
  padding-left: 0 !important;
}
::v-deep .el-input--prefix .el-input__inner {
  padding-left: 0 !important;
}
::v-deep .el-input__prefix i {
  opacity: -1 !important;
}
::v-deep .el-input__suffix-inner i {
  opacity: -1 !important;
}
.tianzhao {
  background-color: #19be6b;
}
.dataInputer {
  width: 120px !important;
}
.model {
  width: 98%;
  height: auto;
  margin: 0 auto;
  margin-top: 20px;
}
.department {
  width: 99%;
  height: 5000px;
  margin: 0 auto;
  margin-bottom: 10px;
  height: auto;
}

.block {
  border-radius: 4px;
  border: 1px solid #dcdfe6;
  position: absolute;
  top: 46px;
  right: 13%;
}
#refrsh {
  position: absolute;
  top: 52px;
  right: 11%;
}

.newadd {
  position: absolute;
  top: 40px;
  right: 3%;
  height: 40px;
  color: #fff;
  line-height: 15px;
  text-align: center;
  font-size: 15px;
  border-radius: 5px;
  display: inline-block;
  background: #19be6b;
}
.newaddPrint {
  position: absolute;
  top: 72px;
  right: 3%;
  height: 40px;
  color: #fff;
  line-height: 15px;
  text-align: center;
  font-size: 15px;
  border-radius: 5px;
  display: inline-block;
  background: #19be6b;
}
.newaddnew {
  position: absolute;
  top: 40px;
  right: 10%;
  height: 40px;
  color: #fff;
  line-height: 15px;
  text-align: center;
  font-size: 15px;
  border-radius: 5px;
  display: inline-block;
  background: #19be6b;
}
.modelBox {
  height: 175px;
  width: 90%;
  margin: 25px 0px 15px 40px;
}
#modelItem {
  width: 118px;
  height: 77px;
  float: left;
  margin-right: 10px;
  margin-bottom: 10px;
  border-radius: 5px;
  border: 1px solid #dcdee2;
  display: flex;
  flex-direction: column;
  justify-content: center;
  cursor: pointer;
}

#modelItem span {
  margin: 0 auto;
  display: inline-block;
  width: 110px;
  height: 20px;
  text-align: center;
  line-height: 20px;
}

#text {
  font-weight: 500;
}
#textn {
  font-size: 14px;
  font-weight: normal;
  color: #6a6b6d;
}
.isActive {
  // border-color: rgb(45, 140, 240);
  box-shadow: rgb(92, 173, 255) 0px 0px 3px;
  background-color: rgb(45, 140, 240);
  // color: #fff;
}
.s1 {
  color: #fff;
}
.s2 {
  color: #fff;
}

.jiansuo-box {
  width: 94%;
  margin: auto;
  background: aliceblue;
  height: 80px;
  border-radius: 5px;
  border: 1px solid #dcdee2;
  text-align: center;
  line-height: 80px;
  display: flex;
  flex-direction: row;
  justify-content: space-around;
  align-items: center;
}
.kaiguan {
  display: inline-block;
  margin-left: 5px;
}

.kuangBox {
  display: inline;
  margin-right: 9%;
}
.span_top {
  position: relative;
  font-size: 15px;
  line-height: 50px;
}
.bed {
  width: 200px;
  position: relative;
  left: 0%;
}
.mod_box {
  margin-top: -60px;
  width: 2150px;
  margin-left: 15%;
}
.morsePrint {
  height: 40px;
  border-bottom: 1px solid #e8eaec;
}
.morseText {
  float: left;
  color: #303133;
  margin-top: 8px;
}

@media screen and (min-width: 1200px) and (max-width: 1365px) {
  .mod_box {
    width: 2150px;
    margin-left: -35%;
  }
  .block {
    border-radius: 4px;
    border: 1px solid #dcdfe6;
    position: absolute;
    top: 46px;
    right: 19%;
  }
  #refrsh {
    position: absolute;
    top: 52px;
    right: 16%;
  }

  .newadd {
    position: absolute;
    top: 40px;
    right: 4%;
    height: 40px;
    color: #fff;
    line-height: 15px;
    text-align: center;
    font-size: 15px;
    border-radius: 5px;
    display: inline-block;
    background: #19be6b;
  }

  .newaddPrint {
    position: absolute;
    top: 72px;
    right: 4%;
    height: 40px;
    color: #fff;
    line-height: 15px;
    text-align: center;
    font-size: 15px;
    border-radius: 5px;
    display: inline-block;
    background: #19be6b;
  }
  .kuangBox {
    display: inline;
    margin-right: 4%;
  }
  .bed {
    width: 42%;
    position: relative;
    left: 0%;
  }
}
@media screen and (min-width: 1366px) and (max-width: 1600px) {
  .mod_box {
    width: 2150px;
    margin-left: -21%;
  }
  .block {
    border-radius: 4px;
    border: 1px solid #dcdfe6;
    position: absolute;
    top: 46px;
    right: 18%;
  }
  #refrsh {
    position: absolute;
    top: 52px;
    right: 15%;
  }

  .newadd {
    position: absolute;
    top: 40px;
    right: 4%;
    height: 40px;
    color: #fff;
    line-height: 15px;
    text-align: center;
    font-size: 15px;
    border-radius: 5px;
    display: inline-block;
    background: #19be6b;
  }

  .newaddPrint {
    position: absolute;
    top: 72px;
    right: 4%;
    height: 40px;
    color: #fff;
    line-height: 15px;
    text-align: center;
    font-size: 15px;
    border-radius: 5px;
    display: inline-block;
    background: #19be6b;
  }
}
@media screen and (min-width: 1800px) {
  .mod_box {
    width: 2150px;
    margin-left: -7%;
  }
  .block {
    border-radius: 4px;
    border: 1px solid #dcdfe6;
    position: absolute;
    top: 46px;
    right: 13%;
  }
  #refrsh {
    position: absolute;
    top: 52px;
    right: 11%;
  }

  .newadd {
    position: absolute;
    top: 40px;
    right: 3%;
    height: 40px;
    color: #fff;
    line-height: 15px;
    text-align: center;
    font-size: 15px;
    border-radius: 5px;
    display: inline-block;
    background: #19be6b;
  }
  .newaddPrint {
    position: absolute;
    top: 72px;
    right: 3%;
    height: 40px;
    color: #fff;
    line-height: 15px;
    text-align: center;
    font-size: 15px;
    border-radius: 5px;
    display: inline-block;
    background: #19be6b;
  }
}
</style>
